package com.link.base.base.report.controller;

import com.link.base.base.report.model.GuideReport;
import com.link.base.base.report.model.SalesAmount;
import com.link.base.base.report.service.GuideReportService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author unknown
 * @date unknown
 */
@Controller
@RequestMapping("link/guideReport")
public class GuideReportController extends BasicController<GuideReport> {

    @Resource
    private GuideReportService guideReportService;

    @Override
    public BasicService<GuideReport> getBasicService() throws Exception {
        return guideReportService;
    }

    /**
     * 逻辑是展示当前登陆人所创建的所有商机所处的各阶段汇总。
     * 就是商机上现在有个字段叫当前阶段，按照商机所处的阶段对商机数进行汇总。
     *
     * @return
     */
    @RequestMapping(value = "/queryOptyStageNum", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryOptyStageNum(GuideReport record, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryOptyStageNum(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 一周商机数量汇总表：逻辑是当前登陆人创建的今日以前6天一直到今天每天新建的商机数
     *
     * @return
     */
    @RequestMapping(value = "/queryNewOptyNum", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryNewOptyNum(GuideReport record, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryNewOptyNum(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 查询客户状态数量汇总
     *
     * @return
     */
    @RequestMapping(value = "/queryAccntStatusNum", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryAccntStatusNum(GuideReport record, HttpSession session,
                                                   HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryAccntStatusNum(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 客户关键节点推进报表
     *
     * @return
     */
    @RequestMapping(value = "/queryAccntKeyNum", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryAccntKeyNum(GuideReport record, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryAccntKeyNum(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 产品销售分析（销售额）
     *
     * @return
     */
    @RequestMapping(value = "/queryProOrderSalesMoney", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryProOrderSalesMoney(GuideReport record, HttpSession session,
                                                       HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryProOrderSalesMoney(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 产品销售分析（订单数量）
     *
     * @return
     */
    @RequestMapping(value = "/queryProOrderSalesNum", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryProOrderSalesNum(GuideReport record, HttpSession session,
                                                     HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryProOrderSalesNum(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 销售订单状态分析
     *
     * @return
     */
    @RequestMapping(value = "/querySalesOrderStatusNum", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> querySalesOrderStatusNum(GuideReport record, HttpSession session,
                                                        HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.querySalesOrderStatusNum(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 企点客服接待统计
     *
     * @return
     */
    @RequestMapping(value = "/queryAccountPeopleNum", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryAccountPeopleNum(GuideReport record, HttpSession session,
                                                     HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryAccountPeopleNum(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 商机预算top10
     *
     * @return
     */
    @RequestMapping(value = "/queryOptyBudgtTop10", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryOptyBudgtTop10(GuideReport record, HttpSession session,
                                                   HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryOptyBudgtTop10(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 产品收藏top10
     *
     * @return
     */
    @RequestMapping(value = "/queryProductCollTop10", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryProductCollTop10(GuideReport record, HttpSession session,
                                                     HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryProductCollTop10(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 本周销量情况
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/querySalesAmountReport", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> querySalesAmountReport(GuideReport record, HttpSession session,
                                                      HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<SalesAmount> list = guideReportService.querySalesAmountReport(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 标签组信息
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/queryAccnttagReport", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryAccnttagReport(GuideReport record, HttpSession session,
                                                   HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryAccnttagReport(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 标签组详情信息
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/queryAccnttagItemReport", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryAccnttagItemReport(GuideReport record, HttpSession session,
                                                       HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryAccnttagItemReport(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }


    /**
     * 客户类型分析
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/queryAccntTypeReport", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryAccntTypeReport(GuideReport record, HttpSession session,
                                                    HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryAccntTypeReport(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 本周客户连接总结
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/queryContonectAccntReport", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryContonectAccntReport(GuideReport record, HttpSession session,
                                                         HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryContonectAccntReport(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 本周商机汇总分析
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/queryOptyStudyReport", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryOptyStudyReport(GuideReport record, HttpSession session,
                                                    HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryOptyStudyReport(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 本周订单数量分析
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/queryOrderNumReport", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryOrderNumReport(GuideReport record, HttpSession session,
                                                   HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.queryOrderNumReport(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 销售产品TOP10
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/querySalesProductTop10Report", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> querySalesProductTop10Report(GuideReport record, HttpSession session,
                                                            HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.querySalesProductTop10Report(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 品牌维度查询销售额
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/querySaleAmountByBrand", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> querySaleAmountByBrand(GuideReport record, HttpSession session,
                                                      HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.querySaleAmountByBrand(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 导购维度查询销售额
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/querySaleAmountByGuide", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> querySaleAmountByGuide(GuideReport record, HttpSession session,
                                                      HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<GuideReport> list = guideReportService.querySaleAmountByGuide(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 查询上周导购通过导购助手接待的客户数量
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/queryAccntTypeNumLastWeek", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryAccntTypeNumLastWeek(GuideReport record, HttpSession session,
                                                         HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            GuideReport qr = guideReportService.queryAccntTypeNumLastWeek(record);
            result.put("result", qr);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }


    /**
     * 统计每周销售额（用于销售周报）
     *
     * @param record
     * @return
     */
    @RequestMapping(value = "/querySalesAmountWeekReport", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> querySalesAmountWeekReport(GuideReport record, HttpSession session,
                                                          HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<SalesAmount> list = guideReportService.querySalesAmountWeekReport(record);
            result.put("result", list);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }
}
